package com.shwread.android.qysw.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.shwread.android.qysw10000209.R;
import com.squareup.picasso.Picasso;

import java.text.DecimalFormat;
import java.util.List;

import logic.bean.OrderBean;

/**
 * Created by lexy on 16/6/4.
 */
public class TicketOrderListAdapter
        extends
        BaseAdapter {
    private List<OrderBean.OrderBeanList> orderBeanList;
    private Context mContext;
    public TicketOrderListAdapter(Context mContext, List<OrderBean.OrderBeanList> orderBeanList) {
        this.mContext = mContext;
        this.orderBeanList = orderBeanList;
    }

    @Override
    public int getCount() {
        return orderBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return  orderBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        SubOrderViewHolder holder;
        if (convertView == null) {
            holder = new SubOrderViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.goods_detail_item, null);
            holder.goods_detail_item_image = (ImageView) convertView.findViewById(R.id.goods_detail_item_image);
            holder.goods_detail_item_name_tv = (TextView) convertView.findViewById(R.id.goods_detail_item_name_tv);
            holder.goods_detail_item_original_price_tv = (TextView) convertView.findViewById(R.id.goods_detail_item_original_price_tv);
            holder.goods_detail_item_original_count_tv = (TextView) convertView.findViewById(R.id.goods_detail_item_original_count_tv);
            holder.goods_detail_item_classify_tv = (TextView) convertView.findViewById(R.id.tvOrderListProperty);
            holder.tvOrderListMoreDetail = (TextView) convertView.findViewById(R.id.tvOrderListMoreDetail);
            holder.v_deliver =convertView.findViewById(R.id.v_deliver);
            convertView.setTag(holder);
        }
        else {
            holder = (SubOrderViewHolder) convertView.getTag();
        }

//        if (position==orderBeanList.size()-1){
//            holder.v_deliver.setVisibility(View.GONE);
//        }else{
//            holder.v_deliver.setVisibility(View.VISIBLE);
//        }

        Picasso.with(mContext).load(orderBeanList.get(position).getTicketImg()).error(R.drawable.atlas_default_img)
                .placeholder(R.drawable.atlas_default_img).into(holder.goods_detail_item_image);
        holder.goods_detail_item_name_tv.setText(orderBeanList.get(position).getSpotName());
        DecimalFormat df = new DecimalFormat("0.0");
        holder.goods_detail_item_original_price_tv.setText("￥"+df.format(orderBeanList.get(position).getTotalMoney()/100));
        holder.goods_detail_item_classify_tv.setText(orderBeanList.get(position).getPropertyName());
        int status = orderBeanList.get(position).getStatus();
        if (status==10){
            holder.tvOrderListMoreDetail.setText("待使用");
            holder.tvOrderListMoreDetail.setTextColor(Color.parseColor("#ff8000"));
            holder.goods_detail_item_original_count_tv.setText("数量："+orderBeanList.get(position).getUsableAmount());
        }else if(status==20){
            holder.tvOrderListMoreDetail.setText("已使用");
            holder.tvOrderListMoreDetail.setTextColor(Color.parseColor("#f1040f"));
            holder.goods_detail_item_original_count_tv.setText("数量："+(orderBeanList.get(position).getAmount()-orderBeanList.get(position).getUsableAmount()));
        }else if(status==30){
            holder.tvOrderListMoreDetail.setText("已过期");
            holder.tvOrderListMoreDetail.setTextColor(Color.parseColor("#1BA9FB"));
            holder.goods_detail_item_original_count_tv.setText("数量："+orderBeanList.get(position).getUsableAmount());
        }
        return convertView;
    }
    private class SubOrderViewHolder {
        private TextView       goods_detail_item_name_tv;
        private TextView       goods_detail_item_original_price_tv;
        private TextView       goods_detail_item_original_count_tv;
        private TextView       goods_detail_item_classify_tv;
        private TextView       tvOrderListMoreDetail;
        private ImageView 		goods_detail_item_image;
        private View v_deliver;
    }
}